#include <REGX52.H>

sbit SCL=P1^4;
sbit SDA=P1^5;

void IIC_START()
{
	SDA=1;
	SCL=1;
	SDA=0;
	SCL=0;
}

void IIC_STOP()
{
	SDA=0;
	SCL=1;
	SDA=1;
}

void IIC_SendByte(unsigned char Byte)
{
	unsigned char i;
	for(i=0;i<8;i++)
	{
		SDA=Byte&(0x80>>i);
		SCL=1;
		SCL=0;
	}
}

unsigned char IIC_ReceiveByte()
{
	unsigned char Byte,i;
		SDA=1;
	for(i=0;i<8;i++)
	{		
		SCL=1;
		if(SDA) Byte|=(0x80>>i);
		SCL=0;
	}
	return Byte;
}

void IIC_SendAck(unsigned char AckBit)
{
	SDA=AckBit;
	SCL=1;
	SCL=0;
}

unsigned char IIC_Receivebit()
{
	unsigned char Ackbit=0;
	SDA=1;
	SCL=1;
	Ackbit=SDA;
	SCL=0;
	return Ackbit;
}



